import React from 'react';
import { inject, observer } from 'mobx-react';
import {WeaDialog,WeaRightMenu,WeaNewScroll,WeaFormItem,WeaSearchGroup} from "ecCom"
import {Button} from "antd"
import {WeaTableNew,WeaSwitch} from 'comsMobx';
const WeaTable = WeaTableNew.WeaTable;
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

@observer
export default class CptLog extends React.Component{
    componentWillReceiveProps(nextProps){
      
    }
    shouldComponentUpdate(){
        return true;
    }
    render(){
        const {visible,tableStore,} = this.props;
        return (
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@4oapbr`}
                title={getLabel(31709,"日志查看")}
                visible={visible}
                buttons={this.getBottomButtons()}
                icon="icon-coms-fa"
                iconBgcolor="#f14a2d"
                onCancel={this.cancel}
                style={{width:850,height:500}}
            >
                <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@wa32au`} datas={this.getRightMenu()} onClick={this.onRightMenuClick.bind(this)}  >
                    <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@w07t7c`} height={"100%"}>
                        {this.getFormItems()}
                        <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@h578a3`} needTigger={true} title={getLabel(32940,'日志信息')}  showGroup={true} >
                            <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@ihcz6x`} 
                                comsWeaTableStore={tableStore}
                                hasOrder={true}
                                needScroll={true}
                            />
                        </WeaSearchGroup>
                    </WeaNewScroll>
                </WeaRightMenu>
            </WeaDialog>
        )
    }
    getBottomButtons(){
        let btnArr = []; 
        btnArr.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@c8uyjy@search`}  type="primary" onClick={this.search}>{getLabel(197,'搜索')}</Button>)  
        btnArr.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@qjvkmc@close`}  type="primary" onClick={this.cancel}>{getLabel(309,'关闭')}</Button>)  
        return btnArr;
    }
    getRightMenu(){
        let btns = [];
		btns.push({
			icon: <i className='icon-coms-search'/>,
			content:getLabel(197,'搜索'),
			key:0
		});
    	return btns
    }
    onRightMenuClick(key){
		if(Number(key)==0){
			this.search()
		}
    }
    getFormItems=()=>{
        const {condition,form} = this.props;
        const {isFormInit} = form;
        let group = [];
        isFormInit && condition.length>0 && condition.map((c,i) =>{
          let items = [];
          c.items.map((fields,index) => {
            items.push({
              com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@rp7424@${index}`}
                  label={`${fields.label}`}
                  labelCol={{span: `${fields.labelcol}`}}
                  wrapperCol={{span: `${fields.fieldcol}`}}>
                        <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@9r4fht@${index}`} fieldConfig={fields} form={form}  />
                  </WeaFormItem>),
              colSpan:1,
            })
          });
          group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@thm740@${i}`} needTigger={true} title={c.title}  showGroup={c.defaultshow} items={items}/>)
        });
        return group;
    }
    cancel=()=>{
        typeof this.props.onCancel == "function" && this.props.onCancel()
    }
    search=()=>{
        typeof this.props.onSearch == "function" && this.props.onSearch()
    }
}